# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
import sys
class Solution:
    def isValidBST(self, root: TreeNode) -> bool:
        interval=(-sys.maxsize,sys.maxsize)
        def judgenode(node,interval):
            if not node:
                return True
            else:
                if node.val<=interval[0] or node.val>=interval[1]:
                    return False
            return judgenode(node.left,(interval[0],node.val)) and judgenode(node.right,(node.val,interval[1]))
        return judgenode(root,interval)

'''
执行用时：
44 ms
, 在所有 Python3 提交中击败了
97.36%
的用户
内存消耗：
16 MB
, 在所有 Python3 提交中击败了
69.21%
的用户
'''